import axios from 'axios';
//如果出现进度条没有显示：一定是你忘记了引入样式了
import nprogress from 'nprogress';
import "nprogress/nprogress.css";

let requests = axios.create({
    baseURL: '/api',
    timeout: 5000,
});

requests.interceptors.request.use((config) => {
    // 添加请求头
    // config.headers.Authorization = window.sessionStorage.getItem('token');
    nprogress.start();
    return config;
})

requests.interceptors.response.use(
    (res) => {
       nprogress.done();
       return res.data;
    },
    (error) => {
        alert("服务器响应数据失败");
    }
);

//这里的代码是暴露一个axios实例
export default requests;
